#1 导入依赖
from lxml import etree
from lxml.etree import tostring

#2 发送请求和获取响应
#3 解析html文件，返回一个节点树的对象
html_text = etree.parse("test.html",etree.HTMLParser())


#4 获取根节点html的元素
bookname = html_text.xpath("/html/body/ul/li/p[3]/a/text()")
print(bookname)
# bookname = html_selector.xpath("//li/p[3]/a/text()")
# bookname = html_selector.xpath("//a[@id='dianzishu']/text()")
# bookname = html_selector.xpath("//a[@id='dianzishu']")[0]
# print(type(bookname))#<class 'list'>
# print(tostring(bookname))